package groupchooser;

import java.util.ArrayList;
import java.util.Dictionary;

public class GroupChooserHandler {
    
    int numOfStudents;
    
    ArrayList<Student> studentList;
    ArrayList<Student> allStudentList;
    String[] students = {
        "Gert",
        "Rúni",
        "Andrias",
        "Bárður",
        "Regin",
        "Robbie",
        "Kristjan",
        "Dánjal Jákup",
        "Svenn Óli",
        "Atli",
        "Hans Jacob",
        "Grímur",
        "Símin",
        "Jógvan",
        "Bejamin"
    };
        
    public GroupChooserHandler()
    {
        allStudentList = new ArrayList<>();
        for(String name : students)
        {
            allStudentList.add(new Student(name));
        }
    }
    
    public ArrayList<Student> getAllStudents()
    {
        return allStudentList;
    }
    
    private ArrayList<Student> getStudentList(boolean includeAll)
    {
        ArrayList<Student> temp = new ArrayList<>();
        for(Student s : allStudentList)
        {
            if(includeAll || s.getIsAttending())
                temp.add(s);
        }
        return temp;
    }
        
    public ArrayList<Group> generateGroup(int maxNum, boolean includeAll)
    {
        studentList = getStudentList(includeAll);
        ArrayList<Group> groups = new ArrayList<>();
        
        numOfStudents = studentList.size();
        int groupNumber = 1;
        while(numOfStudents > 0)
        {
            Group g = new Group(groupNumber);
            for(int i = 0; i < maxNum; i++)
            {   
                int numStudent = (int)(Math.random() * numOfStudents);
                Student s = studentList.get(numStudent);
                studentList.remove(numStudent);
                g.addStudent(s);
                numOfStudents--;
                
            }
            groups.add(g);
            
            groupNumber++;
        }
        
        return groups;
    }
    
}
